package com.warm.spring.config;

import com.warm.spring.mvc.filter.MyFilterA;
import com.warm.spring.mvc.filter.MyFilterB;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Date: 2019/11/25 15:51
 * @Author: LChuang
 * @Description:
 */
@Configuration
public class FilterConfig {

    /**
     * 注册第三方过滤器
     * 功能与spring mvc中通过配置web.xml相同
     * 可以添加过滤器锁拦截的 URL，拦截更加精准灵活
     */
    @Bean
    public MyFilterB myFilter(){
        return new MyFilterB();
    }

    @Bean
    public FilterRegistrationBean myFilterRegistration(){
        FilterRegistrationBean register = new FilterRegistrationBean();
        register.setFilter(myFilter());
        // 过滤全部请求
        register.addUrlPatterns("/*");
        // 顺序 -- order的数值越小 则优先级越高
        register.setOrder(1);
        return register;
    }
}
